# -*- coding: utf-8 -*-
# @Time : 2018/12/24 16:20
# @Author : Administrator
# @File : httptestV3.py
# @Project : python_demo
# @title : 测试用例
import http.client

from py41.http_test.read_data import Common


class AgileTest():
    def __init__(self):
        self.con=http.client.HTTPConnection("localhost",8088)

    def test_login(self,username,password,savelogin,expect):
        self.con.request(method="POST", url="/agileone/index.php/common/login",
                    body="username="+username+"&password="+password+"&savelogin="+savelogin,
                    headers={"Content-Type": "application/x-www-form-urlencoded"})
        # 获取响应
        res_login = self.con.getresponse().read().decode()
        # print(res_login)
        if res_login==expect:
            print("test ok")
        else:
            print("test ko")

if __name__ == '__main__':
    # AgileTest().test_login("admin","","true","password_invalid")
    co=Common()
    result=co.read_data("testdata.csv")
    # print(result[1]["username"])
    # print(result[1]["password"])
    # print(result[1]["savelogin"])
    # print(result[1]["expect"])
    # print(len(result))

    for i in range(0,len(result)):
        print(result[i]["username"])
        username=result[i]["username"]
        password = result[i]["password"]
        savelogin = result[i]["savelogin"]
        expect = result[i]["expect"]
        AgileTest().test_login(username,password,savelogin,expect)
